<?php 
/**
* @author Oliver Leisalu, Inditel Meedia
* @package DomFg
* @subpackage Input
*/
class DomFgFile extends DomFgInput {
	
	public function __construct( $name = NULL ) {
		parent::__construct( $name );
	}
	
	public function width( $width ) {
		$this->style .= 'width: ' . $width . (is_int($width) ? 'px' : NULL).';';
		return $this;
	}

	
	protected static function getReturnValue( $value ) {
		if( is_array($value['tmp_name']) == true ) {
			$result = array();
			foreach( $value['tmp_name'] as $k => $tmp_name ) {
				$result[$k] = array( $tmp_name, $value['name'][$k] );
			}
			return $result;
		} else {
			return array( $value['tmp_name'], $value['name'] );
		}
	}
	
	/**
	* @return Array where 0 is tmp_name and 1 is name
	*/
	public static function parsePost( $name, &$post ) {
		$r = self::getReturnValue( $_FILES[$name] );
		return self::getReturnValue( $_FILES[$name] );
	}
	
	public function render() {
		$renderer = $this->getRenderer();
		$renderer->assign('input', $this );
		return $renderer->fetch('Input/File.html');
	}
	

}
?>